package com.xinqi.modules.sys.log.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.sys.log.domain.AsyncLogEntity;
import com.xinqi.modules.sys.log.dto.rsp.AsyncLogResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.Map;

/**
 * @Author：yyzhen
 * @Package：com.xinqi.modules.sys.log.convert
 * @Project：XingqiClass-Cloud-Plus
 * @name：OperatorLogConvert
 * @Date：2023/8/25 10:23
 * @Filename：OperatorLogConvert
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class AsyncLogConvert {

    @Mappings({@Mapping(expression = "java(map.get(\"title\").toString())", target = "title"),
        @Mapping(expression = "java(map.get(\"type\").toString())", target = "type"),
        @Mapping(expression = "java(map.get(\"operaType\").toString())", target = "operaType"),
        @Mapping(expression = "java(Long.parseLong(map.get(\"operatorId\").toString()))", target = "operatorId"),
        @Mapping(expression = "java(map.get(\"operatorUrl\").toString())", target = "operatorUrl"),
        @Mapping(expression = "java(map.get(\"operatorIp\").toString())", target = "operatorIp"),
        @Mapping(expression = "java(map.get(\"paramJson\").toString())", target = "paramJson"),
        @Mapping(expression = "java(Integer.parseInt(map.get(\"status\").toString()))", target = "status"),
        @Mapping(expression = "java(map.get(\"errorMsg\").toString())", target = "errorMsg")})
    public abstract AsyncLogEntity create(Map<String, Object> map);

    public abstract AsyncLogResultDTO convert(AsyncLogEntity s);

}
